#!/usr/bin/python
# -*- coding:utf-8 -*-

import time
import logging
import re

# 配置系统日志
def logConf(is_debug, file_name):
    if is_debug:
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s %(filename)s+%(lineno)d [%(levelname)s] %(message)s', filemode='w')
    else:
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s %(filename)s+%(lineno)d [%(levelname)s] %(message)s',
                            filename=file_name,
                            filemode='w')

# 返回 YYYYMMDD-HHMMSS
def getSysTime():
    time_tuple = time.localtime(time.time())  # 获取当前的时间返回一个时间元组
    fmt = '%Y%m%d-%H%M%S'  # 格式化时间
    return time.strftime(fmt, time_tuple)  # 把传入的元组按照格式，输出字符串

# 从一个URL截取域名
def parse_domain(url):
    obj = re.search(r'.*?://([\w-]+\.+[\w-]+\.[\w-]+)/?', url, re.I)
    return obj.group(1)